<?php 
include dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."WxPayPubHelper.php";
class wxpaysaoma {
 
	private $config;
	/**
	*	支付入口
	**/
	
	function  __construct($config=null,$config2=null){
     
			$this->config = array_merge($config, $config2);
        
           
	}
	
	public function submit(){
  
	//使用统一支付接口
	$unifiedOrder = new UnifiedOrder_pub();
	$amount = trim($this->config['api_pay_amount'])*100;  
     //$amount = 1;
    $notify_url=  SHOP_SITE_URL.'/api/payment/wxpaysaoma/notify_url.php';   //通知URL

    
	//设置统一支付接口参数
	//设置必填参数
	//appid已填,商户无需重复填写
	//mch_id已填,商户无需重复填写
	//noncestr已填,商户无需重复填写
	//spbill_create_ip已填,商户无需重复填写
	//sign已填,商户无需重复填写
	//iconv("gb2312","utf-8//IGNORE",
	$unifiedOrder->setParameter("body",$this->config['subject']);//商品描述
	//自定义订单号，此处仅作举例
	$out_trade_no = $this->config['order_list'][0]['pay_sn'];
	$unifiedOrder->setParameter("out_trade_no",$out_trade_no);//商户订单号 
	$unifiedOrder->setParameter("total_fee",$amount);//总金额
	$unifiedOrder->setParameter("notify_url",$notify_url);//通知地址 
	$unifiedOrder->setParameter("trade_type","NATIVE");//交易类型
	//非必填参数，商户可根据实际情况选填
	//$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号  
	//$unifiedOrder->setParameter("device_info","XXXX");//设备号 
	$unifiedOrder->setParameter("attach","111");//附加数据 
	//$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
	//$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 
	//$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 
	//$unifiedOrder->setParameter("openid","XXXX");//用户标识
	//$unifiedOrder->setParameter("product_id","XXXX");//商品ID
   
	//获取统一支付接口结果
	$unifiedOrderResult = $unifiedOrder->getResult();

	//商户根据实际情况设置相应的处理流程
	if ($unifiedOrderResult["return_code"] == "FAIL") 
	{
		//商户自行增加处理流程
		echo "通信出错：".$unifiedOrderResult['return_msg']."<br>";
	}
	elseif($unifiedOrderResult["result_code"] == "FAIL")
	{
		//商户自行增加处理流程
		echo iconv("utf-8","gb2312//IGNORE","错误代码：".$unifiedOrderResult['err_code']."<br>");
		echo iconv("utf-8","gb2312//IGNORE","错误代码描述：".$unifiedOrderResult['err_code_des']."<br>");
	}
	elseif($unifiedOrderResult["code_url"] != NULL)
	{
		$qrcode='http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js';
		//从统一支付接口获取到code_url
		$code_url = $unifiedOrderResult["code_url"];
		$saomiao="微信安全支付，请扫我";
		//		//参数1表示图像大小，取值范围1-10；参数2表示质量，取值范围'L','M','Q','H'
		if($unifiedOrderResult["code_url"] != NULL)
		{
					$hehe='	var url = "'.$code_url.'";var qr = qrcode(10, "M");
					qr.addData(url);qr.make();var wording=document.createElement("p");
					wording.innerHTML = "'.$saomiao.'";	
					var code=document.createElement("DIV");
					code.innerHTML = qr.createImgTag();
					var element=document.getElementById("qrcode");
					element.appendChild(wording);element.appendChild(code);';
		}

		//$def_url='<html><head></head><body><div align="center" id="qrcode"> </div></body><script src="'.$qrcode.'">111</script><script>'.$hehe.'</script></html>';
		
$def_url='<img id="payQRImg" class="qrcode2" src="https://paya.swiftpass.cn/pay/qrcode?uuid=' .$code_url.'" alt="二维码" style="border-width:0px;">';

$qian=<<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>微信扫码支付</title>
    <link rel="stylesheet" type="text/css" href="./api/payment/wxpaysaoma/statics/comm.css" />
<!--[if IE 6]>
     <script type="text/javascript" src="./api/payment/wxpaysaoma/statics/iepng.js"></script> 
     <script type="text/javascript">
     EvPNG.fix('.search a.seaIcon i,.m-menu-all h3 em,.nav-cart-btn i.f-cart-icon,a.u-cart s,.u-mui-tab a.u-menus s,.u-mui-tab li.f-cart a.u-menus i,.u-mui-tab li.f-both-top a.u-menus,.u-mui-tab li.f-both-bottom a.u-menus,.i-ctrl a s,.g-list li cite,.f-list-sorts li.m-value s,.nav-main li.f-nav-thanks span,.u-float-list a i,.cartEmpty i,.transparent-png');
     </script>
 <![endif]-->
    <link rel="stylesheet" type="text/css" href="./api/payment/wxpaysaoma/statics/WeixinPay.css?date=150214" />
    <style type="text/css" media="screen">
        body{font-family:"Microsoft YaHei",Helvetica,Verdana,Arial,Tahoma;font-size:14px;line-height:1.6;color:#303030;background:url(../images/wxbj.png) repeat scroll 0 0 #D4D5D7;}a img{border:0 none;}a{color:#374673;}a:hover{color:#5770BB;}a:active{color:#374673;}.weixin2{margin:0 auto 25px;width:920px;background:url(../images/wxbg_h.png) repeat-x #FFF;background-position:-5px -60px;box-shadow:0 1px 1px rgba(0,0,0,0.35);position:relative;}.wx_box{background:url(../images/wxbg_mail_box.png) repeat-x bottom left;bottom:-10px;overflow:hidden;padding:60px 170px 100px;position:relative;}.wx_box_corner{background:url(../images/wxbg_h.png) no-repeat;height:30px;position:absolute;top:0;width:6px;}.wx_box_corner.left{background-position:0 0;left:-5px;}.wx_box_corner.right{background-position:0 -30px;right:-5px;}.msg_default_box{background-color:#445F85;border:1px solid #2B4D69;border-radius:3px;color:#FFF;letter-spacing:6px;padding:12px 0;text-align:center;}.msg_default_box i{margin-left:-16px;}.msg_default_box p{display:inline-block;font-size:16px;letter-spacing:normal;text-align:left;vertical-align:middle;}.msg_default_box strong{color:#FFF;display:block;font-size:15px;font-weight:400;}.msg_box{background-color:#4CA698;border:1px solid #259483;border-radius:3px;box-shadow:0 1px 2px rgba(0,0,0,0.2);color:#FFF;letter-spacing:6px;padding:12px 0;text-align:center;}.msg_box i{margin-left:-16px;}.msg_box p{display:inline-block;font-size:16px;letter-spacing:normal;text-align:left;vertical-align:middle;}.msg_box strong{color:#FFF;display:block;font-size:15px;font-weight:400;}.wx_box_area{text-align:center;}.wx_header{background:url(../images/wx_icon.png);background-position:0 -235px;height:66px;margin-bottom:7px;}.wx_logo{padding-bottom:0;padding-top:18px;text-align:center;}.pay_box .msg_box,.pay_box .msg_default_box{display:inline-block;width:288px;}.wx_img_wrapper{display:block;width:306px;height:306px;margin:0 auto;position:relative;}.wx_img_wrapper .qrcode{max-height:290px;max-width:290px;min-height:200px;min-width:200px;padding:7px;}.wx_img_wrapper .qrcode2{height:301px;width:301px;padding:0;}.icon_wx{background:url(../images/wx_icon.png);display:inline-block;height:60px;vertical-align:middle;width:60px;}.qr_default .icon_wx{background-position:0 -60px;}.qr_default #qr_normal,.qr_succ #qr_normal{display:block;}.qr_default .msg_box{display:none;}.qr_succ .msg_default_box{display:none;}.guide{display:none;margin-left:-101px;position:absolute;top:0;}.wx_money{text-align:center;border-bottom:1px solid #D0D8E4;color:#585858;font-size:60px;font-weight:400;line-height:68px;padding-bottom:20px;padding-top:50px;width:100%;}.wx_hd{border-bottom:3px solid #E0E3EB;width:100%;position:relative;height:70px;}.wx_hd_img{width:60px;height:60px;display:block;background-color:#FFF;display:inline-block;padding-left:12px;padding-right:14px;position:relative;top:34px;left:250px;}.wx_hd .icon_wx{background-position:11px -130px;}.wx_left{float:left;text-align:left;}.wx_right{float:right;text-align:right;color:#303030;}.wx_pay{padding:30px 0 60px;}.wx_pay p{width:100%;display:block;overflow:hidden;height:20px;line-height:20px;color:#8E8E8E;font-size:14px;}.wx_kf{width:100%;border-top:3px solid #D0D8E4;padding:20px 0 0;overflow:hidden;}.wx_kf_img{float:left;width:30px;height:35px;display:block;background-position:0 -193px;}.wx_kf_wz{float:left;color:#303030;}.msg_default_box1{width:258px;margin:0 auto;padding:12px 0;border:1px solid #2b4d69;background-color:#445f85;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;letter-spacing:6px;text-align:center;color:#FFF;}.msg_default_box1 p{display:inline-block;vertical-align:middle;letter-spacing:normal;text-align:left;font-size:16px;color:#FFF;}.icon60_qr{width:60px;height:60px;display:inline-block;vertical-align:middle;background:transparent url(../images/wx_icon_pay.png) no-repeat 0 0;margin-right:20px;}.msg_default_box1 .icon60_qr{background-position:0 -60px;}.qr_succ{border:1px solid #259483;background-color:#4ca698;}.pay_succ{border:1px solid #148F64;background-color:#20B481;}.pay_error{border:1px solid #D13A03;background-color:#f15a22;}.qr_succ .icon60_qr,.pay_succ .icon60_qr{background-position:0 0;}.pay_error .icon60_qr{background-position:0 -122px;}.refresh_time{margin-top:20px;}
    </style>
   <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>


    <script language="javascript" type="text/javascript">

    $(function() {
    $("#divRTool").remove();
    var e = $("#qr_box");
    var c = $("#guide");
    c.css({
        left: "50%",
        opacity: 0
    });
    e.hover(function() {
        c.css("display", "block").stop().animate({
            marginLeft: "+156px",
            opacity: 1
        },
        900, "swing",
        function() {
            c.animate({
                marginLeft: "+143px"
            },
            300)
        })
    },
    function() {
        c.stop().animate({
            marginLeft: "-101px",
            opacity: 0
        },
        "400", "swing",
        function() {
            c.hide()
        })
    });
    var d = $("#hidShopID").val();
    var b = 0;
    var a = function() {
        $.getJSON("" + d + "",
        function(f) {
            if (f.state == 0) {
                if ($("#hidIsBuyPay").val() == "0") {
                   
                } else {
                   
                }
            } else {
                b++;
                setTimeout(a, 3000 + parseInt(b / 20) * 1000)
            }
        })
    };
    setTimeout(a, 10000)
});
</script>
</head>
<body>
    <input name="hidShopID" type="hidden" id="hidShopID" value="150828170326589026" />
    <input name="hidIsBuyPay" type="hidden" id="hidIsBuyPay" value="0" />
    <div class="wx_header">
        <div class="wx_logo">
            <img title="微信支付" alt="微信支付标志" src="./api/payment/wxpaysaoma/statics/wxlogo_pay.png?v=1" /></div>
    </div>
    <div class="weixin">
        <div class="weixin2">
            <b class="wx_box_corner left pngFix"></b><b class="wx_box_corner right pngFix"></b>
            <div class="wx_box pngFix">
                <div class="wx_box_area">
                    <div class="pay_box qr_default">
                        <div class="area_bd"><span class="wx_img_wrapper" id="qr_box">
EOT;

$jinr =<<<EOT
 <img style="left: 50%; opacity: 0; display: none; margin-left: -101px;" class="guide pngFix" src="./api/payment/wxpaysaoma/statics/wxwebpay_guide.png" alt="" id="guide" />
                        </span>
                            <div class="msg_default_box1"><i class="icon60_qr pngFix"></i>
                                <p>
                                    请使用微信<br />
                                    扫一扫完成支付
                                </p>
                            </div>
                            <div class="msg_box"><i class="icon_wx pngFix"></i>
                                <p><strong>扫描成功</strong>请在手机确认支付</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="wx_hd">
                    <div class="wx_hd_img icon_wx"></div>
                </div>
                <div class="wx_money"><span>￥</span>
EOT;
$dingdan =<<<EOT
.00元</div>
                <!--支付订单号-->
                <div class="wx_pay">
                    <p><span class="wx_left">支付订单号</span><span class="wx_right">
EOT;



$out_trade=<<<EOT
</span></p>
                </div>
                <div class="wx_kf">
                    
                </div>
            </div>
        </div>
    </div>
<script language="javascript" type="text/javascript" src="./api/payment/wxpaysaoma/statics/check.js"></script>
</body>
</html>
EOT;
		
$bee = $this->config['api_pay_amount'];	
echo $qian. $def_url . $jinr. $amount/100 . $dingdan . $out_trade_no .$out_trade . $hou."<i id='bee'>$bee</i>";

	exit;
			//商户自行增加处理流程
			//......
		}

	}

 }

?>